<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>保姆预订系统 - 用户登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .auth-container {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 450px;
            overflow: hidden;
        }

        .auth-header {
            background: linear-gradient(90deg, #3498db, #2980b9);
            color: white;
            text-align: center;
            padding: 25px 20px;
        }

        .auth-header h1 {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 5px;
        }

        .auth-header p {
            font-size: 14px;
            opacity: 0.9;
        }

        .auth-content {
            padding: 25px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .form-group input {
            width: 100%;
            padding: 14px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 15px;
            transition: all 0.3s;
        }

        .form-group input:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }

        .btn-login {
            background: linear-gradient(90deg, #3498db, #2980b9);
            color: white;
            border: none;
            padding: 14px;
            width: 100%;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .btn-login:active {
            transform: translateY(0);
        }

        .register-link {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #666;
        }

        .register-link a {
            color: #3498db;
            text-decoration: none;
            font-weight: 500;
        }

        .register-link a:hover {
            text-decoration: underline;
        }

        .message {
            padding: 12px;
            border-radius: 6px;
            margin-bottom: 20px;
            font-size: 14px;
            text-align: center;
            display: none;
        }

        .error-message {
            background-color: #feeceb;
            color: #e74c3c;
            border: 1px solid #fadbd8;
        }

        .success-message {
            background-color: #eafaf1;
            color: #2ecc71;
            border: 1px solid #d5f5e3;
        }

        @media (max-width: 480px) {
            .auth-container {
                border-radius: 0;
                box-shadow: none;
            }

            body {
                padding: 0;
                background: white;
            }
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="auth-header">
            <h1>保姆预订系统</h1>
            <p>欢迎登录，使用我们的家政服务</p>
        </div>

        <div class="auth-content">
            <div id="errorMessage" class="message error-message"></div>
            <div id="successMessage" class="message success-message"></div>

            <form action="login" method="POST" id="loginForm">
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" id="username" name="username" placeholder="请输入用户名" required>
                </div>

                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" id="password" name="password" placeholder="请输入密码" required>
                </div>

                <button type="submit" class="btn-login">登录</button>
            </form>

            <div class="register-link">
                没有账号？<a href="register.jsp">立即注册</a>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const errorMessage = document.getElementById('errorMessage');
            const successMessage = document.getElementById('successMessage');
            const form = document.getElementById('loginForm');

            // 从Java作用域获取消息
            <%
                // 使用不同变量名避免与内置session对象冲突
                HttpSession userSession = request.getSession(false);
                String errorMsg = null;
                String successMsg = null;

                if (userSession != null) {
                    // 获取消息
                    errorMsg = (String) userSession.getAttribute("errorMessage");
                    successMsg = (String) userSession.getAttribute("successMessage");

                    // 清除消息避免重复显示
                    userSession.removeAttribute("errorMessage");
                    userSession.removeAttribute("successMessage");
                }
            %>

            // 处理错误消息
            <% if (errorMsg != null) { %>
                errorMessage.textContent = '<%= errorMsg %>';
                errorMessage.style.display = 'block';
                setTimeout(() => {
                    errorMessage.style.display = 'none';
                }, 5000);
            <% } %>

            // 处理成功消息
            <% if (successMsg != null) { %>
                successMessage.textContent = '<%= successMsg %>';
                successMessage.style.display = 'block';
                setTimeout(() => {
                    successMessage.style.display = 'none';
                }, 5000);
            <% } %>

            // 表单提交验证
            form.addEventListener('submit', function(e) {
                errorMessage.style.display = 'none';
                successMessage.style.display = 'none';

                const username = document.getElementById('username').value.trim();
                const password = document.getElementById('password').value;

                if (!username) {
                    showError('请输入用户名');
                    e.preventDefault();
                    return;
                }

                if (!password) {
                    showError('请输入密码');
                    e.preventDefault();
                    return;
                }
            });

            function showError(message) {
                errorMessage.textContent = message;
                errorMessage.style.display = 'block';
            }
        });
    </script>
</body>
</html>